﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using LDSP.BRL;

namespace ImplementationInitialization
{
    public class ImportCodificationResult
    {
        public DataTable CodificationItemResult { get; set; }
        public DataTable StandardItemResult { get; set; }
        public DataTable ExposureDraftItemResult { get; set; }

        public DataTable CodificationAttachmentResult { get; set; }
        public DataTable StandardAttachmentResult { get; set; }
        public DataTable ExposureDraftAttachmentResult { get; set; }

        public ImportCodificationResult()
        {
            CodificationItemResult = InitialResultItemTable();
            CodificationAttachmentResult = InitialAttachmentTable();

            ExposureDraftItemResult = InitialResultItemTable();
            ExposureDraftAttachmentResult = InitialAttachmentTable();

            StandardItemResult = InitialResultItemTable();
            StandardAttachmentResult = InitialAttachmentTable();
        }

        private DataTable InitialResultItemTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_EXCEL_FILE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_EXCEL_SHEET);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_TYPE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_ITEM_NAME);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_MESSAGE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_SUCCESS);

            return dt;
        }

        private DataTable InitialAttachmentTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_ITEM_NAME);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_TYPE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_MESSAGE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_SUCCESS);

            return dt;
        }

        public void AddItemResult(string excelFile, DocType type, string excelSheet, string name, string message, bool success)
        {
            DataTable dt = GetItemResult(type);
            string s = success ? "成功" : "失败";

            dt.Rows.Add(excelFile, excelSheet, type.ToString(), name, message, s);
        }

        private DataTable GetItemResult(DocType type)
        {
            DataTable result = null;
            switch (type)
            {
                case DocType.法律法规:
                    {
                        result = CodificationItemResult;
                        break;
                    }
                case DocType.标准:
                    {
                        result = StandardItemResult;
                        break;
                    }
                case DocType.征求意见稿:
                    {
                        result = ExposureDraftItemResult;
                        break;
                    }
                default: break;
            }
            return result;
        }

        public void AddAttachmentResult(string name, DocType type, string message, bool success)
        {
            DataTable dt = GetAttachmentResult(type);
            string s = success ? "成功" : "失败";

            dt.Rows.Add(name, type.ToString(), message, s);
        }

        private DataTable GetAttachmentResult(DocType type)
        {
            DataTable result = null;
            switch (type)
            {
                case DocType.法律法规:
                    {
                        result = CodificationAttachmentResult;
                        break;
                    }
                case DocType.标准:
                    {
                        result = StandardAttachmentResult;
                        break;
                    }
                case DocType.征求意见稿:
                    {
                        result = ExposureDraftAttachmentResult;
                        break;
                    }
                default: break;
            }
            return result;
        }

        public void ClearCodification()
        {
            CodificationItemResult.Rows.Clear();
            CodificationAttachmentResult.Rows.Clear();
        }

        public void ClearStandard()
        {
            StandardItemResult.Rows.Clear();
            StandardAttachmentResult.Rows.Clear();
        }

        public void ClearExposureDraft()
        {
            ExposureDraftAttachmentResult.Rows.Clear();
            ExposureDraftAttachmentResult.Rows.Clear();
        }

        public void ClearAll()
        {
            ClearCodification();
            ClearStandard();
            ClearExposureDraft();
        }
    }
}
